Page({
  data: {
    activeTab: 'all',
    activeTabIndex: 0,
    coupons: [
      { id: 1, value: '¥7', name: '无门槛立减卷', date: '2025-8-01到期' },
      { id: 2, value: '¥7', name: '无门槛立减卷', date: '2025-8-01到期' },
      { id: 3, value: '¥7', name: '无门槛立减卷', date: '2025-8-01到期' },
      { id: 4, value: '¥7', name: '无门槛立减卷', date: '2025-8-01到期' }
    ],
    newestCoupons: [],
    expiringCoupons: []
  },
  handleTabTap(e) {
    const tab = e.currentTarget.dataset.tab;
    let tabIndex = 0;
    if (tab === 'newest') {
      tabIndex = 1;
    } else if (tab === 'expiring') {
      tabIndex = 2;
    }
    this.setData({
      activeTab: tab,
      activeTabIndex: tabIndex
    });
    // 这里可以添加点击后页面跳转逻辑，例如
    if (tab === 'newest') {
      wx.navigateTo({
        url: '/pages/newestCoupons/newestCoupons' // 替换为实际最新获得优惠券页面路径
      });
    } else if (tab === 'expiring') {
      wx.navigateTo({
        url: '/pages/expiringCoupons/expiringCoupons' // 替换为实际即将过期优惠券页面路径
      });
    }
  },
  handleSwiperChange(e) {
    const index = e.detail.current;
    let tab = 'all';
    if (index === 1) {
      tab = 'newest';
    } else if (index === 2) {
      tab = 'expiring';
    }
    this.setData({
      activeTab: tab,
      activeTabIndex: index
    });
  }
});